<template>
	<view class="c-wrap app_flex-aicjcc" @click="uploadImg">
		<slot>
			<image src="../../static/images/icon-upload-add.png" mode=""></image>
		</slot>
	</view>
</template>

<script>
	export default {
		props: {
			customImg: {
				type: String,
				default: ''
			}
		},
		data() {
			return {

			}
		},
		created() {

		},
		methods: {
			uploadImg() {
				uni.chooseImage({
					count: 1,
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: `${this.$g_config.requestUrl}/api/common/upload`,
							filePath: tempFilePaths[0],
							name: 'file',
							success: (uploadFileRes) => {
								console.log(uploadFileRes);
								let url = JSON.parse(uploadFileRes.data).url
								this.$emit('change', url)
							}
						});
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.c-wrap {
		width: 100%;
		height: 100%;
		border-radius: 20rpx;
		background-color: #F2F3F7;
		font-size: 0;

		image {
			width: 100%;
			height: 100%;
		}
	}
</style>
